<?php
class News{
	public $link;
	function __construct($linkstr){
		$this->link = $linkstr;
	}
	
	
	public function getAllNews(){
		$strsql = "select * from news order by id desc";
		$result = mysqli_query($this->link, $strsql);
		return mysqli_fetch_all($result);
	}
	
	public function getNewsById($id){
		$strsql = "select * from news where id = ".$id;
		$result = mysqli_query($this->link, $strsql);
		$data = mysqli_fetch_all($result);
		return $data[0];
	}
	
	public function addNews($title, $content){
		$strsql = "insert into news (title, content) values ('".$title."', '".$content."')";
		$query = mysqli_query($this->link, $strsql);
		if ($query){
			return true;
		}else{
			return false;
		}
	}
	
	public function editNews($title, $content, $id){
		$strsql = "update news set title = '".$title."', content = '".$content."' where id = ".$id;
		$query = mysqli_query($this->link, $strsql);
		if ($query){
			return true;
		}else{
			return false;
		}
	}
	
	public function deleteNews($id){
		$strsql = "delete from news where id = ".$id;
		$query = mysqli_query($this->link, $strsql);
		if ($query){
			return true;
		}else{
			return false;
		}
	}
	
}











?>